var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("TearImgTool"),
    i = t("TexturePlus"),
    n = (function () {
        function t() {
            this.textures = [];
            this.parentNode = null;
        }
        t.prototype.play = function (t, e, o) {
            this.parentNode = t;
            var a = this.addTextureNode(e);
            a.node.setPosition(a.node.parent.convertToNodeSpaceAR(o));
        };
        t.prototype.downRect = function () {
            for (
                var t = function (t) {
                        var o = e.textures[t].node,
                            a = cc.v2(o.position),
                            i = cc.v2(a.x - Math.floor(100 * Math.random()) - 250 * (t + 1), a.y + 200),
                            n = [a, a.add(i).mul(0.5), i],
                            r = 1.5 + 1.5 * t;
                        o.runAction(cc.sequence([cc.scaleTo(r / 2, 0, 1), cc.scaleTo(r / 2, 1, 1)]));
                        o.runAction(
                            cc.sequence([
                                cc.spawn(
                                    cc.bezierBy(r, n).easing(cc.easeOut(3)),
                                    cc.rotateTo(r, 90).easing(cc.easeOut(3)),
                                    cc.fadeOut(1.5)
                                ),
                                cc.callFunc(function () {
                                    QLooperNode.putNode(o);
                                }, e)
                            ])
                        );
                    },
                    e = this,
                    o = 0;
                o < this.textures.length;
                o++
            )
                t(o);
            this.textures.length = 0;
        };
        t.prototype.addTextureNode = function (t) {
            var e = new cc.Node(),
                o = e.addComponent(i.default);
            e.parent = this.parentNode;
            o.texture = t;
            this.textures.push(o);
            return o;
        };
        t.prototype.addTextureNode2 = function (t) {
            var e = null.getComponent(i.default);
            null.parent = this.parentNode;
            e.texture = t;
            this.textures.push(e);
            return e;
        };
        t.prototype.centerSplit = function (t) {
            var e = t.height,
                o = t.width,
                a = cc.v2(-(0.5 * o + 10), 0.4 * e - e / 2),
                i = cc.v2(0.5 * o + 10, 0.6 * e - e / 2);
            this.useLineCutPolygon(a, i, t, !1);
        };
        t.prototype.useLineCutPolygon = function (t, e, o, i) {
            void 0 === i && (i = !0);
            for (var n = this.textures.length - 1; n >= 0; n--) {
                var r = this.textures[n],
                    s = t.clone(),
                    c = e.clone();
                if (i) {
                    s = r.node.convertToNodeSpaceAR(t);
                    c = r.node.convertToNodeSpaceAR(e);
                }
                var p = a.default.lineCutPolygon(s, c, r.polygon);
                p.length <= 0 || this.splitTexture(r, p, o);
            }
        };
        t.prototype.splitTexture = function (t, e, o) {
            t.polygon = e[0];
            for (var a = 1; a < e.length; a++) {
                var i = this.addTextureNode(o);
                i.node.setPosition(t.node.position);
                i.polygon = e[a];
            }
        };
        t.prototype.clearAll = function () {
            for (var t = 0; t < this.textures.length; t++) QLooperNode.putNode(this.textures[t].node);
            this.textures.length = 0;
        };
        return t;
    })();
o.default = n;
